package demo06

import scala.collection.mutable.ListBuffer

/**
 * @author xiaoZhao
 * @date 2022/7/11
 * @describe 可变对列表
 */
object Test05_ListBuffer {
  def main(args: Array[String]): Unit = {
    // 1. 创建一个可变的列表
    val listBuffer = new ListBuffer[Int]()
    val listBuffer1 = ListBuffer(10, 29, 90, 24)
    println(listBuffer)
    println(listBuffer1)
    println("====================")
    // 2。添加元素
    listBuffer.append(12, 78)
    listBuffer1.prepend(67, 46)

    listBuffer.insert(1, 89, 21)
    println(listBuffer)
    println(listBuffer1)
    println("====================")

    21 +=: 35 +=: listBuffer += 21 += 32
    println(listBuffer)
    println("====================")

    // 3.合并list
    val listBuffer2 = listBuffer ++ listBuffer1
    println(listBuffer)
    println(listBuffer1)
    println("====================")

    listBuffer ++= listBuffer1
    println(listBuffer)
    println(listBuffer1)

    listBuffer ++=: listBuffer1
    println(listBuffer)
    println(listBuffer1)

    // 4.修改元素 底层调用update方法
    listBuffer1(3) = 90
    println(listBuffer1)

    // 5.删除元素
    listBuffer1.remove(2)
    listBuffer1 -= 21
    println(listBuffer1)
  }
}
